package gold.contest;

import gold.utils.InputUtil;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * Created by fanzhenyu02 on 2020/6/27.
 * common problem solver template.
 */
public class LC5991 {
    public long startExecuteTime = System.currentTimeMillis();


    class Solution {
        public int[] rearrangeArray(int[] nums) {
            int[] res = new int[nums.length];
            int pIdx = 0, nIdx = 1;
            for (int i = 0; i < nums.length; i++) {
                if (nums[i] > 0) {
                    res[pIdx] = nums[i];
                    pIdx += 2;
                } else {
                    res[nIdx] = nums[i];
                    nIdx += 2;
                }
            }

            return res;
        }
    }

    public void run() {
        Solution solution = new Solution();
        System.out.println(Arrays.toString(solution.rearrangeArray(InputUtil.toIntegerArray("[3,1,-2,-5,2,-4]"))));
        System.out.println(Arrays.toString(solution.rearrangeArray(InputUtil.toIntegerArray("[-1,1]"))));
    }

    public static void main(String[] args) throws Exception {
        LC5991 an = new LC5991();
        an.run();

        System.out.println("\ncurrent solution total execute time: " + (System.currentTimeMillis() - an.startExecuteTime) + " ms.");
    }
}
